// 主窗口

const { BrowserWindow } = require("electron");
const path = require("path");
// electron 区分环境
const isDev = require("electron-is-dev");
const { contextMenu } = require("../modules/sysMenu");

let mainWindow;
exports.createWindow = () => {
  mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: false,
      contextIsolation: true,
      sandbox: false,
      // enableRemoteModule: true,
      // devTools: true,
      preload: path.resolve(__dirname, "../scripts/preload.js"),
    },
  });
  // 加载 src下的应用
  if (isDev) {
    mainWindow.loadURL("http://localhost:5173/home");
  } else {
    mainWindow.loadFile(
      path.resolve(__dirname, "../../renderer/pages/main/index.html")
    );
  }

  // 创建右键菜单
  contextMenu(mainWindow);

  mainWindow.openDevTools();
};

// mainWindow 窗口，接收渲染进程 控制端 发送的消息
exports.send = (channel, ...args) => {
  console.log("🚀 ~ main.js:41 ~ args:", args);

  mainWindow.webContents.send(channel, ...args);
};
